<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>JS阻塞渲染</title>
  </head>
  <body>
    <h1>Xumaozeng</h1>
    <button>change</button>

    <script>
      const h1 = document.querySelector("h1");
      const btn = document.querySelector("button");

      // 死循环指定的时间
      function delay(duration) {
        /* let start = Date.now();
        while (Date.now() - start < duration) {} */
        /* setTimeout(function () {
          console.log("setTimeout");
        }, duration); */
        Promise.resolve().then(function () {
          console.log("promise");
        });
      }

      btn.onclick = function () {
        h1.textContent = "hhh";
        delay(3000);
      };
    </script>
  </body>
</html>
